function dropdown(that){
    var oEvent = arguments.callee.caller.arguments[0] || event;
    oEvent.stopPropagation();
    var offset = $(that).offset();
    var top=offset.top-$(window).scrollTop();
    var index = $(that).parents('tr').data('index');
    $('.layui-nav-child').each(function (key) {
        if (key != index) {
            $(this).hide();
        }
    })
    if($(document).height() < top+$(that).next('ul').height()){
        $(that).next('ul').css({
            'padding': 10,
            'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
            'min-width': 'inherit',
            'position': 'absolute'
        }).toggle();
    }else{
        $(that).next('ul').css({
            'padding': 10,
            'top':$(that).parent('td').height() / 2 + $(that).height(),
            'min-width': 'inherit',
            'position': 'absolute'
        }).toggle();
    }
}

//自定义方法
var action= {
    set_value: function (field, id, value) {
        layList.baseGet(layList.Url({
            a: 'set_value',
            q: {field: field, id: id, value: value}
        }), function (res) {
            layList.msg(res.msg);
        });
    },
}


layList.tool(function (event,data,obj) {
    switch (event) {
        case 'delete':
            var url=layList.U({a:'delete',q:{id:data.id}});
            $eb.$swal('delete',function(){
                $eb.axios.get(url).then(function(res){
                    if(res.status == 200 && res.data.code == 200) {
                        $eb.$swal('success',res.data.msg);
                        obj.del();
                    }else
                        return Promise.reject(res.data.msg || '删除失败')
                }).catch(function(err){
                    $eb.$swal('error',err);
                });
            })
            break;
        case 'open_image':
            $eb.openImage(data.image);
            break;
    }
});

layList.switch('set_status',function (odj,value) {
    if(odj.elem.checked==true){
        layList.baseGet(layList.Url({a:'set_status',p:{status:1,id:value}}),function (res) {
            layList.msg(res.msg);
        });
    }else{
        layList.baseGet(layList.Url({a:'set_status',p:{status:0,id:value}}),function (res) {
            layList.msg(res.msg);
        });
    }
});


//快速编辑
layList.edit(function (obj) {
    var id=obj.data.id,value=obj.value;
    action.set_value(obj.field,id,value);
});

$(document).click(function (e) {
    $('.layui-nav-child').hide();
});